package com.example.demo.mapper;

import com.example.demo.dto.CommentDto;
import com.example.demo.dto.CommentTeacherDto;
import com.example.demo.dto.DepartmentDto;
import com.example.demo.dto.StudentDto;
import com.example.demo.entity.Student;
import com.example.demo.entity.Teacher;
import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TeacherMapper {

    @Select("select * from teacher limit #{page},#{limit}")
    List<Teacher> select(Integer page,Integer limit);

    //查总数
    @Select("select count(1) from teacher")
    Integer selectTeacherCount();

    @Select("select id,user_name,password from teacher where user_name=#{userName} and password=#{password}")
    Teacher selectByUserName(String userName, String password);

    @Delete("delete from teacher where id=#{id}")
    Integer delById(Integer id);

    @Insert("insert into teacher(name,user_name,password)" +
            " values(#{name},#{userName},#{password})")
    Integer insertTea(Teacher teacher);

    //查询我的课程
//    @Select("SELECT t.name as creat ,d.name,type,score,place,time from department d join teacher t on d.create = t.id limit #{page},#{limit}")
    @Select("select d.*,t.name as creat from department d join teacher t on d.`createby`=t.id where `createby` = #{tId} limit #{page},#{limit}")
    public List<DepartmentDto> selectMyDepPage(Integer page, Integer limit, Integer tId);

    //查询我的课程总数
    @Select("select count(1) from department d join teacher t on d.`createby`=t.id where `createby` = #{tId}")
    Integer selectMyDepCount(Integer tId);

    //根据课程id删除学生选课表
    @Delete("delete from student_dep where department_id=#{depId}")
    Integer delSDByDId(Integer depId);

    @Select("SELECT a.*,d.`name` as d_name,d.id as depId from (select s.*,sd.department_id from student s join student_dep sd on s.id = sd.student_id ) a join department d on a.department_id = d.id where d.createby = #{tId} limit #{page},#{limit}")
    List<StudentDto> stuPage(Integer page,Integer limit,Integer tId);

    @Select("SELECT count(1) from (select s.*,sd.department_id from student s join student_dep sd on s.id = sd.student_id ) a join department d on a.department_id = d.id where d.createby = #{tId}")
    Integer stuPageCount(Integer tId);


    //查询我的评价
    @Select("select s.name as sName,a.* from student s join (select c.*,d.name from comment_teacher c join department d on c.department_id = d.id) a on a.student_id=s.id where a.teacher_id=#{tId} limit #{page},#{limit}")
    List<CommentTeacherDto> selectMyComment(Integer page, Integer limit, Integer tId);

    //查询我的评价总数
    @Select("select count(1) from comment_teacher where teacher_id=#{tId}")
    Integer selectMyCommentCount(Integer tId);


    //修改教师评价
    @Update("update comment_teacher set content = #{content},score =#{score} where id=#{comId}")
    Integer updateComment(String content,Integer score,Integer comId);

}
